﻿using System;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;


namespace IupNET
{
    [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
    public delegate void CdcHardcopyCallback(IntPtr canvas_cobj);

    /// <summary>
    /// This class wraps the cd c api
    /// </summary>
    public static class Cdc
    {

        const string module = "iupnet-c.dll";

        #region DRIVERS
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextNativeWindow();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextIup();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextClipboard();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextPrinter();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextPicture();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextImageRGB();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextDBufferRGB();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextImage();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextDBuffer();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextPDF();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextPS();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextMetafile();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextCGM();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextDGN();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextDXF();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextWMF();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextEMF();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr ContextDebug();
       // [DllImport(module), SuppressUnmanagedCodeSecurity]
       // public static extern IntPtr ContextGL();
        #endregion


        #region CANVAS_GENERAL
        [DllImport(module, EntryPoint = "CreateCanvas")]
        public static extern IntPtr CreateCanvasPtr(IntPtr context, IntPtr data);

        [DllImport(module, EntryPoint = "CreateCanvas")]
        public static extern IntPtr CreateCanvasStr(IntPtr context, string data);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void KillCanvas(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasActivate(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasDeactivate(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasGetContext(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int ContextCaps(IntPtr ctx);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasSimulate(IntPtr canvas, int mode);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasClear(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasFlush(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasSaveState(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasRestoreState(IntPtr canvas, IntPtr state);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void ReleaseState(IntPtr state);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasSetAttribute(IntPtr canvas, string name, string data);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern string CanvasGetAttribute(IntPtr canvas, string name);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasForeground(IntPtr canvas, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasSetForeground(IntPtr canvas, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasBackground(IntPtr canvas, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasSetBackground(IntPtr canvas, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasWriteMode(IntPtr canvas, int mode);

        #endregion

        #region COORDINATE_SYSTEMS
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetSize(IntPtr canvas, [Out]out int width, [Out]out int height, [Out]out double width_mm, [Out]out double height_mm);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasUpdateYAxis(IntPtr canvas, [Out]out int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double FCanvasUpdateYAxis(IntPtr canvas, [Out]out double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasInvertYAxis(IntPtr canvas, int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double FCanvasInvertYAxis(IntPtr canvas, double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasMM2Pixel(IntPtr canvas, double mm_dx, double mm_dy, [Out]out int dx, [Out]out int dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasMM2Pixel(IntPtr canvas, double mm_dx, double mm_dy, [Out]out double dx, [Out]out double dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPixel2MM(IntPtr canvas, int dx, int dy, [Out]out double mm_dx, [Out]out double mm_dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasPixel2MM(IntPtr canvas, double dx, double dy, [Out]out double mm_dx, [Out]out double mm_dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasOrigin(IntPtr canvas, int x, int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasOrigin(IntPtr canvas, double x, double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetOrigin(IntPtr canvas, [Out]out int x, [Out]out int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasGetOrigin(IntPtr canvas, [Out]out double x, [Out]out double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransform(IntPtr canvas, ref double matrix);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasGetTransform(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransformMultiply(IntPtr canvas, ref double matrix);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransformTranslate(IntPtr canvas, double dx, double dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransformScale(IntPtr canvas, double sx, double sy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransformRotate(IntPtr canvas, double angle);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasTransformPoint(IntPtr canvas, int x, int y, [Out]out int tx, [Out]out int ty);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasTransformPoint(IntPtr canvas, double x, double y, [Out]out double tx, [Out]out double ty);
        
        #endregion


        #region WORLD_COORDINATES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasWindow(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetWindow(IntPtr canvas, [Out]out double xmin, [Out]out double xmax, [Out]out double ymin, [Out]out double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasViewport(IntPtr canvas, int xmin, int xmax, int ymin, int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetViewport(IntPtr canvas, [Out]out int xmin, [Out]out int xmax, [Out]out int ymin, [Out]out int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasWorld2Canvas(IntPtr canvas, double xw, double yw, [Out]out int xv, [Out]out int yv);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasCanvas2World(IntPtr canvas, int xv, int yv, [Out]out double xw, [Out]out double yw);

        [DllImport(module,EntryPoint="WCanvasHardcopy"),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasHardcopyPtr(IntPtr canvas, IntPtr context, IntPtr data, CdcHardcopyCallback draw_func);

        [DllImport(module), SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasHardcopy(IntPtr canvas, IntPtr context, string data, CdcHardcopyCallback draw_func);
        #endregion


        #region CLIPPING
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasClip(IntPtr canvas, int mode);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasClipArea(IntPtr canvas, int xmin, int xmax, int ymin, int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasClipArea(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasClipArea(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasGetClipArea(IntPtr canvas, [Out]out int xmin, [Out]out int xmax, [Out]out int ymin, [Out]out int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int FCanvasGetClipArea(IntPtr canvas, [Out]out double xmin, [Out]out double xmax, [Out]out double ymin, [Out]out double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int WCanvasGetClipArea(IntPtr canvas, [Out]out double xmin, [Out]out double xmax, [Out]out double ymin, [Out]out double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasRegionCombineMode(IntPtr canvas, int mode);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasIsPointInRegion(IntPtr canvas, int x, int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasOffsetRegion(IntPtr canvas, int dx, int dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasOffsetRegion(IntPtr canvas, double dx, double dy);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetRegionBox(IntPtr canvas, [Out]out int xmin, [Out]out int xmax, [Out]out int ymin, [Out]out int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetRegionBox(IntPtr canvas, [Out]out double xmin, [Out]out double xmax, [Out]out double ymin, [Out]out double ymax);
        #endregion


        #region PIXELS_AND_MARKS
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPixel(IntPtr canvas, int x, int y, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPixel(IntPtr canvas, double x, double y, int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasMark(IntPtr canvas, int x, int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasMark(IntPtr canvas, double x, double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasMarkType(IntPtr canvas, int type);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasMarkSize(IntPtr canvas, int size);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double WCanvasMarkSize(IntPtr canvas, double size);
        #endregion


        #region LINE_PRIMITVES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasLine(IntPtr canvas, int x1, int y1, int x2, int y2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasLine(IntPtr canvas, double x1, double y1, double x2, double y2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasLine(IntPtr canvas, double x1, double y1, double x2, double y2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasBegin(IntPtr canvas, int mode);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasVertex(IntPtr canvas, int x, int y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasVertex(IntPtr canvas, double x, double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasVertex(IntPtr canvas, double x, double y);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasEnd(IntPtr canvas);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasRect(IntPtr canvas, int xmin, int xmax, int ymin, int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasRect(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasRect(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasArc(IntPtr canvas, int xc, int yc, int w, int h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasArc(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasArc(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasLineStyle(IntPtr canvas, int style);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasLineStyleDashes(IntPtr canvas, ref int dashes, int count);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasLineWidth(IntPtr canvas, int width);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double WCanvasLineWidth(IntPtr canvas, double width_mm);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasLineJoin(IntPtr canvas, int join);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasLineCap(IntPtr canvas, int cap);

        #endregion


        #region FILLED_PRIMITIVES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasBox(IntPtr canvas, int xmin, int xmax, int ymin, int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasBox(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasBox(IntPtr canvas, double xmin, double xmax, double ymin, double ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasSector(IntPtr canvas, int xc, int yc, int w, int h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasSector(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasSector(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasChord(IntPtr canvas, int xc, int yc, int w, int h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasChord(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasChord(IntPtr canvas, double xc, double yc, double w, double h, double angle1, double angle2);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasBackOpacity(IntPtr canvas, int opacity);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasFillMode(IntPtr canvas, int mode);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasInteriorStyle(IntPtr canvas, int style);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasHatch(IntPtr canvas, int style);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasStipple(IntPtr canvas, int w, int h, ref byte fgbg);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasStipple(IntPtr canvas, int w, int h, ref byte fgbg, double w_mm, double h_mm);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasGetStipple(IntPtr canvas, [Out]out int w, [Out]out int h);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPattern(IntPtr canvas, int w, int h, ref int color);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPattern(IntPtr canvas, int w, int h, ref int color, double w_mm, double h_mm);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasGetPattern(IntPtr canvas, [Out]out int w, [Out]out int h);
        #endregion


        #region TEXT_PRIMITIVES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasText(IntPtr canvas, int x, int y, string text);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void FCanvasText(IntPtr canvas, double x, double y, string text);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasText(IntPtr canvas, double x, double y, string text);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasFont(IntPtr canvas, string typeface, int style, int size);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasFont(IntPtr canvas, string typeface, int style, double size);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetFont(IntPtr canvas, StringBuilder typeface, [Out]out int style, [Out]out int size);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetFont(IntPtr canvas, StringBuilder typeface, [Out]out int style, [Out]out double size);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern string CanvasNativeFont(IntPtr canvas, string nativefont);

        [DllImport(module,EntryPoint="CanvasNativeFont"), SuppressUnmanagedCodeSecurity]
        public static extern string CanvasNativeFontPtr(IntPtr canvas, IntPtr ptr); //neede to get the font

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasTextAlignment(IntPtr canvas, int alignment);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double CanvasTextOrientation(IntPtr canvas, double angle);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetFontDim(IntPtr canvas, [Out]out int max_width, [Out]out int height, [Out]out int ascent, [Out]out int descent);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetFontDim(IntPtr canvas, [Out]out double max_width, [Out]out double height, [Out]out double ascent, [Out]out double descent);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetTextSize(IntPtr canvas, string text, [Out]out int width, [Out]out int height);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetTextSize(IntPtr canvas, string text, [Out]out double width, [Out]out double height);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetTextBounds(IntPtr canvas, int x, int y, string text, [Out]int[] rect);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetTextBounds(IntPtr canvas, double x, double y, string text, [Out]double[] rect);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetTextBox(IntPtr canvas, int x, int y, string text, [Out] out int xmin, [Out] out int xmax, [Out] out int ymin, [Out] out int ymax);

        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetTextBox(IntPtr canvas, double x, double y, string text, [Out] out double xmin, [Out] out double xmax, [Out] out double ymin, [Out] out double ymax);
        #endregion

        #region VECTOR_TEXT_PRIMITIVES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasVectorText(IntPtr canvas, int x, int y, string text);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasVectorText(IntPtr canvas, double x, double y, string text);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasVectorTextDirection(IntPtr canvas, int x1, int y1, int x2, int y2);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasVectorTextDirection(IntPtr canvas, double x1, double y1, double x2, double y2);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasVectorTextTransform(IntPtr canvas, ref double matrix);
        [DllImport(module,EntryPoint="CanvasVectorTextTransform"), SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasVectorTextTransformPtr(IntPtr canvas, IntPtr ptr);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasVectorTextSize(IntPtr canvas, int width, int height, string text);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasVectorTextSize(IntPtr canvas, double width, double height, string text);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasVectorCharSize(IntPtr canvas, int size);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern double WCanvasVectorCharSize(IntPtr canvas, double size);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasVectorFontSize(IntPtr canvas, double size_x, double size_y);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetVectorFontSize(IntPtr canvas, [Out]out double size_x, [Out]out double size_y);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern string CanvasVectorFont(IntPtr canvas, string filename);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetVectorTextSize(IntPtr canvas, string text, out int width, out int height);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetVectorTextSize(IntPtr canvas, string text, out double width, out double height);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetVectorTextBounds(IntPtr canvas, string text, int x, int y, [Out]int[] rect);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetVectorTextBounds(IntPtr canvas, string text, double x, double y, [Out] double[] rect);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetVectorTextBox(IntPtr canvas, int x, int y, string text, out int xmin, out int xmax, out int ymin, out int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasGetVectorTextBox(IntPtr canvas, double x, double y, string text, out double xmin, out double xmax, out double ymin, out double ymax);

        #endregion

        #region CLIENT_IMAGES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetImageRGB(IntPtr canvas, [Out]byte[] r, [Out]byte[] g, [Out]byte[] b, int x, int y, int w, int h);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPutImageRectRGB(IntPtr canvas, int iw, int ih, ref byte r, ref byte g, ref byte b, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPutImageRectRGB(IntPtr canvas, int iw, int ih, ref byte r, ref byte g, ref byte b, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPutImageRectRGBA(IntPtr canvas, int iw, int ih, ref byte r, ref byte g, ref byte b, ref byte a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPutImageRectRGBA(IntPtr canvas, int iw, int ih, ref byte r, ref byte g, ref byte b, ref byte a, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPutImageRectMap(IntPtr canvas, int iw, int ih, ref byte index, ref int colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPutImageRectMap(IntPtr canvas, int iw, int ih, ref byte index, ref int colors, double x, double y, double w, double h, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void RGB2Map(int iw, int ih, ref byte r, ref byte g, ref byte b, [Out]byte[] index, int pal_size, [Out]int[] color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CreateBitmap(int w, int h, int type);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void KillBitmap(IntPtr image);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr BitmapGetData(IntPtr image, int dataptr);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void BitmapSetRect(IntPtr image, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPutBitmap(IntPtr canvas, IntPtr image, int x, int y, int w, int h);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPutBitmap(IntPtr canvas, IntPtr image, double x, double y, double w, double h);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetBitmap(IntPtr canvas, IntPtr image, int x, int y);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void BitmapRGB2Map(IntPtr image_rgb, IntPtr image_map);
        #endregion


        #region SERVER_IMAGES
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern IntPtr CanvasCreateImage(IntPtr canvas, int w, int h);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void KillImage(IntPtr image);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasGetImage(IntPtr canvas, IntPtr image, int x, int y);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPutImageRect(IntPtr canvas, IntPtr image, int x, int y, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void WCanvasPutImageRect(IntPtr canvas, IntPtr image, double x, double y, int xmin, int xmax, int ymin, int ymax);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasScrollArea(IntPtr canvas, int xmin, int xmax, int ymin, int ymax, int dx, int dy);
        #endregion

        
        //system
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern string Version();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern string VersionDate();
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int VersionNumber();

        //metafiles
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasPlay(IntPtr canvas, IntPtr ctx, int xmin, int xmax, int ymin, int ymax, IntPtr data);

        //color coding
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int EncodeColor(byte red, byte green, byte blue);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void DecodeColor(int color, out byte red, out byte green, out byte blue);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int EncodeAlpha(int color, byte alpha);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern byte DecodeAlpha(int color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern byte Alpha(int color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern byte Red(int color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern byte Green(int color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern byte Blue(int color);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern int CanvasGetColorPlanes(IntPtr canvas);
        [DllImport(module),SuppressUnmanagedCodeSecurity]
        public static extern void CanvasPalette(IntPtr canvas, int n, ref int color, int mode);


    }
}
